﻿@using System.Collections;
@using ZDSoft.UPMS.Model;
@using ZDSoft.UPMS.Model.SystemPart;
@model ZDSoft.UPMS.Model.BusinessPart.Organization
@{
    Layout = null;
    IList<User> teachers = TempData["Lists"] as IList<User>;
}
<!DOCTYPE html>
<html>
<head>
    <title>Peizhi</title>
    <link href="../../Scripts/PageCreater/Css/All.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="../../Scripts/jquery-1.5.1.js"></script>
    <script language="javascript" type="text/javascript">

        function SubmitPage() {
            var selectedCourseId = "";
            $("input:checkbox[checked='true']", "#Roletable").each(function (i) {
                var id = $(this).attr("id");
                id = id.replace("chk_", "");
                selectedCourseId = selectedCourseId + "," + id;
            });
            $("#selectCoursID").val(selectedCourseId);
            SaveCours();
            $("#teachers").hide();

        }
        function SaveCours() {
            var selectedCourseId = $("#selectCoursID").val();
            var OragainzationID = $("#OragainzationID").val();
            $.ajax({
                url: "/Organization/CoursCreate", //指定要调用的方法
                type: "POST", //指定提交表单的方法
                data: { "selectedCourseId": selectedCourseId, "id": OragainzationID }, //指定要提交的数据
                dataType: "text", //指定返回数据的格式

                success: function () {
                    alert("保存成功！");

                },
                Error: function () {
                    alert("保存失败！");
                }

            });

        }


        function SaveTeachers() {

            var SelectedTeacherId = $("#SelectedTeacherId").val();
            $.ajax({
                url: "/Organization/Creates", //指定要调用的方法
                type: "POST", //指定提交表单的方法
                data: { "SelectedTeacherId": SelectedTeacherId }, //指定要提交的数据
                dataType: "text", //指定返回数据的格式

                success: function () {
                    alert("创建成功！");

                },
                Error: function () {
                    alert("创建失败！");
                }

            });

        }
        function SubmitPageTeacher() {

            var selectedCourseId = "";
            var temp = 0
            $("input:checkbox[checked='true']", "#teacherss").each(function (i) {
                var id = $(this).attr("id");
                id = id.replace("chk_", "");
                selectedCourseId = selectedCourseId + "," + id;

            });
            $("#SelectedTeacherId").val(tempT + selectedCourseId);
            SaveTeachers();
            $("#teachers").hide();
        }

        //清空当前数据
        function teachers(t) {
            tempT = t;
            $("#teachers").show();
            $("input:checkbox", "#teacherss").each(function (i) {
                var id = $(this).attr("id");
                document.getElementById(id).checked = false;
            });
        }

    </script>
</head>
<body>
    <form id="form" method="post">
    <fieldset style="width: 300px;">
        <legend>课程</legend>
        <table id="Roletable" cellpadding="0" cellspacing="0" class="dataGrid">
            <tr>
                <td>
                    选择
                </td>
                <td>
                    课程名称
                </td>
                @foreach (var item in (IList<ZDSoft.UPMS.Model.BusinessPart.Course>)TempData["List"])
                {

                    var hasRole = false;
                    if (Model.TeacherTeachingCourses.Where(o => o.Course.ID == item.ID).Count() > 0)
                    {
                        hasRole = true;
                    }
                    <tr >
                        <td style="cursor: pointer;">
                            @if (hasRole)
                            {
                                <input type="checkbox" id='chk_ @item.ID'  checked="checked"/>
                            }
                            else
                            {
                                <input type="checkbox" id='chk_ @item.ID'  />
                            }
                        </td>
                        <td>
                            @item.Name
                        </td>
                    </tr>
             
                }
            </tr>
        </table>
        <input id="selectCoursID" name="selectCoursID" type="hidden" />
        <input id="OragainzationID" name="OragainzationID" value="@Model.ID"  type="hidden"/>
        <input type="button" onclick="SubmitPage()" value="保存" />
    </fieldset>
    <div id="teachers" style="display: none;">
        <fieldset style="width: 300px; margin-left: 320px; margin-top: -169px;" id="teacher">
            <legend>任课教师</legend>
            <table cellpadding="0" cellspacing="0" class="dataGrid" id="teacherss">
                @if (teachers == null || teachers.Count == 0)
                {
                    <tr>
                        <td>
                            当前机构下没有可用的教师.
                        </td>
                    </tr>
                }
                else
                {
                    foreach (var item in teachers)
                    {<tr>
                        <td>
                            <input type="checkbox" name="cbname"   id='chk_ @item.ID'   />
                        </td>
                        <td>
                            @item.Name
                        </td>
                    </tr>
                    }
                }
            </table>
            <input type="text" style="display: none;" id="SelectedTeacherId" name="SelectedTeacherId" />
            <input type="button" onclick="SubmitPageTeacher()" value="保存" />
        </fieldset>
    </div>
</body>
</html>
